<template>
    <div>
        <van-nav-bar title="欢迎注册" left-text="返回" left-arrow @click-left="logon" />
        <van-field v-model="user.loginName" label="登录名" />
        <van-field v-model="user.password" label="密码" />
        <van-field v-model="user.name" label="昵称" />
        <van-field v-model="user.phone" type="tel" label="手机号" />
        <van-field v-model="user.userAddress" label="收货地址" />
        <van-field v-model="user.email" label="邮箱" />
        <van-button size="small" type="info" @click="getText()">获取邮箱验证码</van-button>
        <van-field v-model="user.yzm" label="验证码" />
        <van-button round block type="info" @click="submit">
            确定
        </van-button>
    </div>
</template>

<script>
import { Toast } from 'vant';
export default {
    name: 'login',
    data() {
        return {
            user: {}
        }
    },
    created() {
    },
    watch: {
    },
    methods: {
        async getText() {
            let res = await this.$http.getLogonText(this.user.email)
            if (res !== undefined && res.meta.status == 200) {
                Toast('邮件发送成功,请勿重复点击');
                // this.$message({
                //     message: '邮件发送成功,请勿重复点击',
                //     type: 'success'
                // });
            }
        },

        async submit() {
            let res = await this.$http.logon(this.user)
            if (res !== undefined && res.meta.status == 200) {
                Toast('恭喜你，注册成功');
                // this.$message({
                //     message: '恭喜你，注册成功',
                //     type: 'success'
                // });
                this.$router.push({
                    path: this.redirect || '/login'
                })
            }
        },
        logon() {
            this.$router.push({
                path: this.redirect || '/login'
            })
        }
    }
}
</script>

<style>
</style>
